Page({
  data: {},

  onLoad() {
    this.refreshBindPhone()
  },

  //  获取绑定手机号情况
  refreshBindPhone() {
    wx.$API['person/refreshBindPhone']()
      .then((res) => {
        console.log(res, '获取绑定手机号情况')
        if (res.data.bindStatus) {
          this.openAdvertising()
        }
      })
      .catch((error) => {
        console.log(error, 'error')
      })
  },
  openAdvertising() {
    wx.redirectTo({
      // url: '/pages/web/web?path=http://192.168.5.117:39802/advertising',
      url: '/pages/web/web?path=https://xwx.gzzmedu.com/advertising',
    })
  },
  getPhoneNumber(e) {
    console.log(e, '这是获取到的手机号')
    if (e.detail.errMsg === 'getPhoneNumber:fail user deny') {
      console.log('用户没有同意给手机号')
      wx.navigateBack({
        delta: 1,
      })
      return
    }
    wx.showLoading({ title: '加载中....' })
    wx.$API['person/bindPhone']({
      code: e.detail.code,
      payWay: 1,
    })
      .then((res) => {
        wx.hideLoading()
        this.openAdvertising()
        console.log(res, '绑定手机号成功')
      })
      .catch((error) => {
        wx.hideLoading()
        console.log(error, 'error')
        wx.showToast({
          icon: 'none',
          title: error,
        })
      })
  },
})
